<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('page_setting');
	$return['commission_money']=$this->sum('commission',array('mid'=>$_SESSION['uid']),'money');
	if(!$return['commission_money']){
		$return['commission_money']=0;
	}
	$return['commission_total']=$this->count('commission',array('mid'=>$_SESSION['uid']));
	$return['num1']=$this->count('commission',array('mid'=>$_SESSION['uid'],'level'=>1));
	$return['num2']=$this->count('commission',array('mid'=>$_SESSION['uid'],'level'=>2));
	$return['list']=array();
	$return['params']=array(
		'level'=>1,
		'page'=>1,
	);
	$return['psize']=20;
	set_html('title',$return['setting']['torder']?:'分销订单');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('mid'=>$_SESSION['uid']);
	$level=intval($_RQ['level']);
	if(!$level){
		$level=1;
	}
	$params['level']=$level;
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('commission',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){
		$order=pdo_get('jy_weishop_order',array('ordersn'=>$item['ordersn']));
		$item['member']=model('core/member')->basic($order['mid']);
		$item['goodsorder']=pdo_get('jy_weishop_order_goods',array('orderid'=>$order['id']));
		$item['goodsorder']['title']=pdo_getcolumn('jy_weishop_goods',array('id'=>$item['goodsorder']['goodsid']),'title');
		$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
		$item['salefee']=price($item['money']-intval($return['pluginset']['renwufee']));
		$item['renwufee']=price(intval($return['pluginset']['renwufee']));
	}
	exi($list);
}
?>